package com.simple.behavior.classandclass.observer;

import java.util.Enumeration;
import java.util.Vector;

/**
 * @author simple
 * @version 1.0
 * @date 2019-01-04 17:07
 * @since 1.0
 */
public abstract class AbstractSubject implements Subject {
    private Vector<Observer> vector = new Vector<>();

    @Override
    public void add(Observer observer) {
        vector.add(observer);
    }

    @Override
    public void del(Observer observer) {
        vector.remove(observer);
    }

    @Override
    public void notifyObservers() {
        Enumeration<Observer> observerEnumeration = vector.elements();
        while (observerEnumeration.hasMoreElements()) {
            observerEnumeration.nextElement().update();
        }
    }
}
